import { request } from "@/utils/request.js"

// 密码登录
export function login(data) {
  console.log("账户:", data)
  return request({
    url: "/ht-auth/oauth/token",
    headers: {
      isToken: false,
    },
    type: "application/x-www-form-urlencoded",
    method: "POST",//GET、POST
    data: {
      auth_type: "password",
      grant_type: "password",
      client_id: "huatai",
      client_secret: "waytale",
      ...data
    }
  });
}
// APP手机号绑定
export function wxLoginBindPhoneApi(data) {
  return request({
    url: "/ht-user/user/wxLoginBindPhone",
    method: "POST",
    data,
  });
}
/**
 * 检测是否绑定手机
 * @returns {*}
 */
export const checkIsExistPhoneApi = () => {
  return request({
    url: '/ht-user/user/checkIsExistPhone',
    method: 'GET'
  })
}
//注册
export function userSmsRegister(data) {
  return request({
    url: "/ht-user/user/userSmsRegister",
    method: "POST",
    headers: {
      isToken: false
    },
    data: data
  });
}

//获取验证码
export function usergGetSms(data) {
  return request({
    url: "/ht-user/user/getSms",
    method: "POST",
    headers: {
      isToken: false
    },
    data: data
  });
}
// 获取幂等值
export function getUUID(data) {
  return request({
    url: "/ht-user/user/getUUID",
    method: "get",
    headers: {
      isToken: false,
      "Content-Type": "application/json"

    },
    data: data
  });
}
// 找回密码
export function forgetPsd(data) {
  return request({
    url: "/ht-user/user/updateUserPassword",
    method: "get",
    headers: {
      isToken: false
    },
    data: data
  });
}

//H5加入企业
export function userAddEnterprise(data) {
  return request({
    url: "/ht-user/enterpriseEmpCheck/shareUserAddEnterprise",
    method: "POST",
    headers: {
      isToken: false
    },
    data: data
  });
}
//短信登录
export function massageUp(data) {

  return request({
    url: "/ht-auth/oauth/token",
    method: "POST",
    type: "application/x-www-form-urlencoded",
    headers: {
      isToken: false
    },
    data: data
  });
}

/**
 * 获取小程序accessToken
 * @returns {Promise<UniNamespace.RequestTask>}
 */
export const getAccessTokenApi = async () => {
  return uni.request({
    url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx0ae1c7463138cd07&secret=e4fe9cf628c947dfe03f6f85b13bcc70',
  })
}

/**
 * 获取手机号
 * @param accessToken
 * @param code
 * @returns {Promise<UniNamespace.RequestTask>}
 */
export const getPhoneNumberApi = async (accessToken, code) => {
  return uni.request({
    url: `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${accessToken}`,
    method: 'POST',
    data: {
      code
    }
  })
}

export const loginByQuicklyAPi = async params => {
  return request({
    url: '/ht-auth/oauth/token',
    method: "POST",
    type: "application/x-www-form-urlencoded",
    headers: {
      isToken: false
    },
    data: params
  })
}
// 公众号code获取
export const csHqAPi = async () => {
  
  console.log();
  
  return request({
    url: `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx58931fc3f38f7daa&redirect_uri=${encodeURIComponent("https://www.gzryzl.com/api/ht-user/user/getGzhAccessToken")}&response_type=code&scope=snsapi_base&state=STATE`,
    // method: "POST",
  })
}
